/* eslint-disable no-unreachable */
/**
 * 表格
 */
import React from 'react';
import { /*Card,*/ Pagination, Table } from 'antd';
import { defaultSimpleInfo, defaultComplexInfo } from './DefaultConfig';
import styles from './index.module.scss';
import { getComponentData } from 'src/services/AnalyseManage/index';
import {
	WD_TYPE,
	COMPLEX_CODE,
	ORDINARY_CODE,
	DL_TYPE,
} from 'src/pages/AnalyseManage/EditReport/components/EditorDataType/EnumConfig';
import { ChartService } from 'src/pages/AnalyseManage/EditReport/components/ChartsType/components/ChartService';
import { DATA_UNIT_TYPES } from 'src/pages/AnalyseManage/EditReport/components/EditorDataType/EnumConfig';
import { CHART_LINK } from 'src/pages/AnalyseManage/EditReport/topics';
import PubSub from 'pubsub-js';
import { digitFormat, transformTreeData } from 'src/libs/utils';

interface treeType {
	title: string;
	dataIndex: string;
	key: string;
	children: Array<treeType>;
}

export interface IProps {
	config: any,
	isCurrent: boolean,
	key: string;
	id: string;
	pageId: string;
	chartLayout: any;
	chartsConfig: Array<any>;
	onValuesChange: ( chartType: string, key: string, values: Object, configType: string ) => void;
	onAllValuesChange: Function;
	tenantCode?: string;
}

class SimpleTable extends ChartService {
	state: any = {
		tableData: [],
		tableTotal: 0,
		tableCurrentPage: 1,
		tablePageSize: 10,
		queryData: [],
		queryTotal: 0,
		queryCurrentPage: 1,
		queryPageSize: 10000,
		columns: [],
		originColumns: [],
		paginationInfo: {},
		eventToken: [],
		dependencies: [],	//	图表联动参数
		isRender: false
	};

	shouldComponentUpdate( nextProps: Readonly<IProps>, nextState: Readonly<{ dependencies: any }>, nextContext: any ): boolean {
		// console.log( JSON.stringify( nextProps ) !== JSON.stringify( this.props ), JSON.stringify( this.state.dependencies ) !== JSON.stringify( nextState.dependencies ) );
		if ( JSON.stringify( nextProps ) !== JSON.stringify( this.props ) ||
			JSON.stringify( nextState ) !== JSON.stringify( this.state ) ||
			JSON.stringify( this.state.dependencies ) !== JSON.stringify( nextState.dependencies ) ) return true;
		return false;
	}

	componentDidUpdate( prevProps: Readonly<any>, prevState: Readonly<{ dependencies: any }>, snapshot?: any ) {
		// const prevColumns = prevProps.config.data.columns;
		// const currentColumns = this.props.config.data.columns;

		const prevComColumns = prevProps.config.data.comColumns;
		const currentComColumns = this.props.config.data.comColumns;

		const prevRows = prevProps.config.data.rows;
		const currentRows = this.props.config.data.rows;

		const prevTarget = prevProps.config.data.target;
		const currentTarget = this.props.config.data.target;

		const currentTableType = this.props.config.data.tableType;
		if ( snapshot.needDataChange ) {
			if ( currentTableType === ORDINARY_CODE && this.props.config.data.columns && this.props.config.data.columns.length && 
				( JSON.stringify( prevProps.config.data ) !== JSON.stringify( this.props.config.data ) || 
				JSON.stringify( this.state.dependencies ) !== JSON.stringify( prevState.dependencies ) ) ) {
				if( prevProps.config.data.openAggregation !== this.props.config.data.openAggregation ) {
					// 如果是否聚合变化了，需要将page 重置为1 
					this.setState( { tableCurrentPage: 1 }, () => {
						this.getDataByColumns();
					} );
				} else {
					this.getDataByColumns();
				}
				
			} else if (
				currentTableType === COMPLEX_CODE && ( ( currentComColumns && currentComColumns.length ) || ( currentRows && currentRows.length ) ) &&
				( currentTarget && currentTarget.length )
			) {
				// 交叉透视表
				if (
					prevComColumns !== currentComColumns ||
					prevRows !== currentRows ||
					prevTarget !== currentTarget ||
					JSON.stringify( prevProps.config.data ) !== JSON.stringify( this.props.config.data ) || 
					JSON.stringify( this.state.dependencies ) !== JSON.stringify( prevState.dependencies )
				) {
					this.getDataByColumns();
				}
			} else {
				// 没有数据时，给予默认数据
				if ( currentTableType === ORDINARY_CODE ) {
					this.setState( { tableData: defaultSimpleInfo.data, columns: defaultSimpleInfo.columns } );
				} else if ( currentTableType === COMPLEX_CODE ) {
					this.setState( { tableData: defaultComplexInfo.data, columns: defaultComplexInfo.columns } );
				}
			}
		}
	}

	getSnapshotBeforeUpdate( prevProps: Readonly<any>, prevState: Readonly<{ dependencies: any }> ): any | null {
		let { config } = this.props;
		let changeObj = Object.create( null );
		//	判断数据字段是否变化了
		if ( JSON.stringify( prevProps.config.data ) !== JSON.stringify( config.data ) ||
			JSON.stringify( this.state.dependencies ) !== JSON.stringify( prevState.dependencies ) ) {
			changeObj.needDataChange = true;
		}

		return changeObj;
	}

	initEvent = async () => {
		const currentColumns = this.props.config.data.columns;
		const currentComColumns = this.props.config.data.comColumns;
		const currentRows = this.props.config.data.rows;
		const currentTarget = this.props.config.data.target;
		const currentTableType = this.props.config.data.tableType;
		if ( currentTableType === ORDINARY_CODE && currentColumns && currentColumns.length ) {
			// 普通表格
			this.getDataByColumns();
		} else if (
			currentTableType === COMPLEX_CODE && ( ( currentComColumns && currentComColumns.length ) || ( currentRows && currentRows.length ) ) &&
			( currentTarget && currentTarget.length )
		) {
			// 交叉透视表
			this.getDataByColumns();
		} else {
			// 没有数据时，给予默认数据
			if ( currentTableType === ORDINARY_CODE ) {
				this.setState( { tableData: defaultSimpleInfo.data, columns: defaultSimpleInfo.columns } );
			} else if ( currentTableType === COMPLEX_CODE ) {
				this.setState( { tableData: defaultComplexInfo.data, columns: defaultComplexInfo.columns } );
			}
		}
		this.setState( {
			isRender: true
		} );
	};


	/**
	 * 计算合并行数
	 * @param colName 列名
	 * @param rowData render当前行的数据
	 * @param dataSource 整个table的数据
	 * @param firstColKeys 第一列的key数组（y轴key数组）
	 * @param rowIndex reder当前行索引
	 * @param colIndex render当前列索引
	 */
	getMergeRowNum = ( colName, rowData, dataSource, firstColKeys, rowIndex, colIndex ) => {
		let n = 0;
		if ( colIndex > 0 ) {
			const curAndParentCols = firstColKeys.filter( ( t, index ) => index <= colIndex );
			// 当前行当前列和父级列与上一行是否相等，相等则不渲染
			const isCurAndParentColEqual = curAndParentCols.every( ( col ) => {
				return rowIndex !== 0 && rowData[col] === dataSource[rowIndex - 1][col];
			} );
			if ( isCurAndParentColEqual ) {
				n = 0;
			} else {
				// 计算当前列从当前行开始到后面需要合并的行数，匹配到不同的则跳出循环不再计数（针对非第一列情况）
				for ( let count = rowIndex; count < dataSource.length; count++ ) {
					const curRowData = dataSource[count];
					if ( rowData[colName] === curRowData[colName] ) {
						n++;
					} else {
						break;
					}
				}
				// 以当前列当前行为基准向左（父级）取出所有可能被合并的新数组以用于筛选
				const arr = dataSource.slice( rowIndex, rowIndex + n );
				// 以第一行的数据作为基准，通过filter找出相同的数据，
				// 即为父级合并的行数，如果父级行数小于子级，则将父级行数赋值给子级
				const stander = arr[0];
				const parentCol = firstColKeys.slice( 0, colIndex );
				for ( let index = 0; index < parentCol.length; index++ ) {
					const col = parentCol[index];
					const parentN = arr.filter( ( t ) => t[col] === stander[col] ).length;
					if ( parentN < n ) {
						n = parentN;
					}
				}
			}
		} else {
			// 第一列，如果当前行与上一行数据相等则当前行不渲染
			if ( rowIndex !== 0 && rowData[colName] === dataSource[rowIndex - 1][colName] ) {
				n = 0;
			} else {
				for ( let count = rowIndex; count < dataSource.length; count++ ) {
					const curRowData = dataSource[count];
					if ( rowData[colName] === curRowData[colName] ) {
						n++;
					} else {
						break;
					}
				}
			}
		}
		return n;
	};

	/**
	 * table Columns render函数
	 * @param value 当前行的值
	 * @param row 当前行数据
	 * @param rowIndex 行索引
	 * @param key 列名
	 * @param firstColList 表头第一列数据
	 * @param colIndex 列索引
	 * @param data 表格数据
	 */
	renderRow = ( value, row, rowIndex, key, firstColList, colIndex, data ) => {
		const firstColKeys = firstColList.map( ( t ) => t.key );
		const obj = {
			children: value,
			props: {
				rowSpan: null,
				colSpan: null,
			},
		};
		obj.props.rowSpan = this.getMergeRowNum( key, row, data, firstColKeys, rowIndex, colIndex );
		return obj;
	};

	setLeafNodeAttr = ( nodes, isSort=false ) => {
		for ( let i = 0; i < nodes.length; i++ ) {
			if ( !nodes[i].children || !nodes[i].children.length ) {
				nodes[i]['width'] = 100; // nodes[i].title.length * 40;
				nodes[i]['ellipsis'] = true;

				if ( isSort ) {
					nodes[i]['sorter'] = ( a, b ) => {
						const tempA = a[nodes[i]['dataIndex']];
						const tempB = b[nodes[i]['dataIndex']];
						if ( typeof tempA === 'number' ) {
							return tempA - tempB;
						} else {
							return tempA.localeCompare( tempB );
						}
						
					};
				}
			} else {
				this.setLeafNodeAttr( nodes[i].children );
			}
		}
		return nodes;;
	}

	renderFirstCol = ( comColumns, data ) => {
		
		let firstCol = {
			title: '',
			dataIndex: 'key',
			key: 'key',
			children: [],
		};
		if ( comColumns.y.length ) {
			const children = comColumns.y.map( ( t, colIndex ) => {
				return {
					title: t.title,
					key: t.key,
					dataIndex: t.key,
					render:
						// colIndex === 0 ?
						// ( value, row, index ) => this.renderRow( value, row, index, t.key, comColumns.y, colIndex, data )
						colIndex !== comColumns.y.length - 1
							? ( value, row, index ) =>
								this.renderRow( value, row, index, t.key, comColumns.y, colIndex, data )
							: undefined,
				};
			} );
			firstCol.children = children;
		}
		return firstCol;
	};

	/**
	 * @author: can
	 * @desc: 通过 columns 获取表格初始化data数据
	 * @param {*}
	 */
	getDataByColumns = async () => {
		const data = this.props.config.data;
		const type = this.props.config.data.tableType;
		let columnsX = [],
			columnsY = [];

		const { columns = [], comColumns = [], rows = [], target = [] } = data;
		const itemInfo = ( item, orderType?, desc? ) => {
			
			return {
				id: item.dataIndex,
				alias: item.alias || desc,
				dataType: item.dataType,
				frontendId: item.frontendId,
				quota: item.modelType === WD_TYPE ? 'WD' : 'DL',
				type: item.type,
				orderType: item.orderType || orderType,
				aggregateType: item.aggregateType || '',
				formatType: item.formatType || '',
				precision: item.precision,
				dataUnit: item.dataUnit || ''
			};
		};
		if ( type === ORDINARY_CODE ) {
			columnsX = columns.map( ( item ) => {
				return itemInfo( item );
			} );
		} else {
			columnsX = [
				...comColumns.map( ( item ) => itemInfo( item ) ),
				...target.map( ( item ) => itemInfo( item, null, item.title ) ),
			];
			columnsY = rows.map( ( item ) => itemInfo( item, 'ASC' ) );
		}
		// const conditions = this.props.config.data.filterFields ? this.props.config.data.filterFields.map( v => v.filterConditions ).flat() : [];
		// 内部筛选 condition
		const filterFieldCondition = this.props.config.data.filterFields
			? this.props.config.data.filterFields.map( ( v ) => v.filterConditions ).flat()
			: [];

		// 筛选组件的 condition
		let filterCompConditions = this.props.config.data.filterConditions || {};
		let newFilterCompConditions = [];
		Object.keys( filterCompConditions ).forEach( ( key ) => {
			newFilterCompConditions = newFilterCompConditions.concat( filterCompConditions[key] );
		} );

		let request = {
			type: 'table',
			dataConfig: {
				// tableAggregate: this.props.config.data.openAggregation || false,
				dataModel: {
					pageId: this.props.pageId,
					customParams: {
						tableAggregate: !this.props.config.data.openAggregation || false,
					},
					conditions: filterFieldCondition.concat( this.state.dependencies, newFilterCompConditions ),
					page: this.state.queryCurrentPage,
					pageSize: this.state.queryPageSize,
					// tableName: 'ORDERS_USCA_BI',
					tableName: this.props.config.data.tableCode || 'ORDERS_USCA_BI',
					x: columnsX,
					y: columnsY,
				},
				tableType: this.props.config.data.tableType || 'normal',
			},
			tenantCode: this.props.tenantCode
		};
		let pageResponse = await getComponentData( request );
		if ( pageResponse.data && pageResponse.data.success ) {
			let { rows = [], columns: comColumns = { x: [], y: [] }, total = 0 } = pageResponse.data.data || {};
			let { columns = [] } = this.props.config.data || {};
			let resColumns = [];
			if ( type === COMPLEX_CODE ) {
				// 合并度量到新的tableData
				const columnsXWD = columnsX.filter( ( t ) => t.quota === 'WD' ).pop();
				const columnsXDL = columnsX.filter( ( t ) => t.quota === 'DL' ).pop();
				const columnsIdList = columnsX.filter( ( t ) => t.quota === 'WD' ).map( s => s.id );
				const targetColumn = target;
				let rowInfo = rows.map( ( v, i ) => {
					// 设置度量的数据单位
					for( let k in v ) {
						const unitItem = targetColumn.find( t => t.title.trim() === k );
						const unit = unitItem && unitItem.dataUnit ? DATA_UNIT_TYPES[unitItem.dataUnit].label : '';
						const precision = unitItem && unitItem.precision;
						v[k] = precision ? v[k].toFixed( precision ) : v[k]; // 保留小数
						v[k] = !isNaN( v[k] ) ? digitFormat( v[k], 3 ) : v[k];	// 千分位格式化
						v[k] = v[k] ? `${v[k]}${unit}` : v[k]; // 单位
					}
					return {
						...v,
						key: i  
					};
				} );;

				if ( columnsXWD && columnsXDL ) {
					// 拖的行的字段名数组
					const keyArr = columnsY.map( ( t ) => t.id );
					// key为行字段拼接的, value为度量对象（此方法用于合并）
					const map = rowInfo.reduce( ( acc, cur ) => {
						// 行字段对应的value组成的数组
						const valueArr = keyArr.map( ( t ) => cur[t] );
						const valueStr = `${valueArr.join( '_' )}`;
						const nameStr = columnsIdList.slice( 0,columnsIdList.length -1 ).map( t => cur[t] );
						let key = null;
						if ( target.length > 1 ) {
							if ( nameStr.length ) {
								key = `${nameStr}_${cur[columnsXWD.id]}`;
							} else {
								key = `${cur[columnsXWD.id]}`;
							}
							target.forEach( ( t ) => {
								acc[valueStr] = {
									...acc[valueStr],
									[`${key}${t.title}`]: cur[t.title],
								};
							} );
						} else {
							// console.log( `${nameStr}_${cur[columnsXWD.id]}` );
							if ( nameStr.length ) {
								key = `${nameStr}_${cur[columnsXWD.id]}`;
							} else {
								key = `${cur[columnsXWD.id]}`;
							}
							acc[valueStr] = {
								...acc[valueStr],
								[key]: cur[columnsXDL.alias],
							};
						}
						return acc;
					}, {} );
					// console.log( map );
					const tableArr = [];
					for ( const key in map ) {
						if ( Object.prototype.hasOwnProperty.call( map, key ) ) {
							const item = map[key]; // 度量对象
							const valueArr = key.split( '_' ); // 将行字段数组切分
							let obj = {}; // 行对象
							keyArr.forEach( ( t, index ) => {
								obj = {
									...obj,
									[t]: valueArr[index],
								};
							} );
							tableArr.push( { ...obj, ...item, key: Math.random() } ); // 行对象和度量对象合并成渲染表格所需的数组
						}
					}
					rowInfo = tableArr;
				}
				// 合并第一列
				const firstCol = this.renderFirstCol( comColumns, rowInfo );
				resColumns = [ firstCol, ...comColumns.x ];
				resColumns = this.setLeafNodeAttr( resColumns );
				// console.log( rowInfo, resColumns );
				this.setState( { queryData: rowInfo, columns: resColumns, queryTotal: total, originColumns: comColumns } );
				this.getTableData();
			} else {
				columns = this.setLeafNodeAttr( columns, true );
				rows = rows.map( ( v, i ) => {
					for( let k in v ) {
						const unitItem = columns.find( t => t.dataIndex === k );
						const unit = unitItem && unitItem.dataUnit ? DATA_UNIT_TYPES[unitItem.dataUnit].label : '';
						const precision = unitItem && unitItem.precision;
						v[k] = precision ? v[k].toFixed( precision ) : v[k]; // 保留小数
						v[k] = !isNaN( v[k] ) ? digitFormat( v[k], 3 ) : v[k];	// 千分位格式化
						v[k] = v[k] ? `${v[k]}${unit}` : v[k]; // 单位
					}

					return {
						...v,
						key: i  
					};
				} );
				this.setState( { queryData: rows, columns: columns, queryTotal: total, originColumns: comColumns } );
				this.getTableData();
			}
		}
	};

	getTableData = () => {
		let { isOpenPage, pageSize = 10, tableType: currentTableType } = this.props.config.data;
		const { tableCurrentPage, queryData } = this.state;
		const startIndex = ( tableCurrentPage - 1 ) * pageSize;
		const endIndex = startIndex + pageSize;
		let data;
		if ( isOpenPage ) {
			data = queryData.slice( startIndex, endIndex );
		} else {
			data = queryData;
			pageSize = queryData.length;
		}
		// console.log( tableCurrentPage );
		if ( currentTableType === COMPLEX_CODE ) {
			const firstCol = this.renderFirstCol( this.state.originColumns, data );
			let resColumns = [ firstCol, ...this.state.originColumns.x ];
			resColumns = this.setLeafNodeAttr( resColumns );
			// console.log( data, resColumns );
			this.setState( { tableData: data, columns: resColumns, tableTotal: queryData.length, tablePageSize: pageSize } );
		} else {
			// console.log( data, queryData );
			this.setState( { tableData: data, tableTotal: queryData.length, tablePageSize: pageSize } );
		}
	}

	// 分页变化时
	handleTableChange = ( currentPage ) => {
		this.setState( {
			tableCurrentPage: currentPage
		}, () => {
			this.getTableData();
		} );
	};

	onShowSizeChange = ( current, pageSize ) => {
		this.setState( {
			tablePageSize: pageSize,
		}, () => {
			this.handleTableChange( 1 );
		} );
	}

	showTableTotal = ( total ) => {
		return `共 ${total} 条`;
	}


	handleLink = ( event ) => {
		if( !this.props.config.mutual.isChainAvailable ) return;

		let dimension = [];
		const currentTableType = this.props.config.data.tableType;

		//	普通表格
		if ( currentTableType === ORDINARY_CODE ) {
			dimension = this.props.config.data.columns;
		} else {
			dimension = this.props.config.data.rows;
		}

		if( !dimension || dimension.length === 0 ) return;
		const dependencies = dimension.filter( v => v.modelType === WD_TYPE ).map( ( item, index ) => {
			return {
				formatType: item.formatType,
				id: [ item.dataIndex ],
				quota: item.modelType === WD_TYPE ? 'WD' : 'DL',
				symbol: 'EQ',
				value: [ event[ item.dataIndex ] ]		//	从原数据中找到item，一一对应字段
			};
		} );

		PubSub.publish( CHART_LINK, {
			publisherId: this.props.id,
			listenerIds: this.props.config.mutual.chartsChainIds,
			dimension: dependencies,
			tableCode: this.props.config.data.tableCode
		} );
	};

	render() {
		const { config } = this.props;
		// const isOpenPage = this.props.config.data;
		const verticalAlignMap = ( type ) => {
			const map = {
				'flex-start': 'top',
				'center': 'middle',
				'flex-end': 'bottom'
			};
			return map[type];
		};
		const {
			tableHeadBackground,
			tableHeadFontFamily,
			tableHeadFontSize,
			tableHeadFontColor,
			tableHeadIsBold,
			tableHeadIsItalic,
			tableHeadIsUnderLine,
			tableHeadAlignHor,
			tableHeadAlignVer,
			tableBorderColor,
			tableBorderWidth,
			tableBodyBackground,
			tableBodyFontFamily,
			tableBodyFontSize,
			tableBodyFontColor,
			tableBodyIsBold,
			tableBodyIsItalic,
			tableBodyIsUnderLine,
			tableBodyAlignHor,
			tableBodyAlignVer,
			tablePaddingTopBottom,
			tablePaddingLeftRight,
			// tilteHight,
		} = config.style;

		const tablePaddingStyle = {
			paddingTop: `${tablePaddingTopBottom}px`,
			paddingBottom: `${tablePaddingTopBottom}px`,
			paddingLeft: `${tablePaddingLeftRight}px`,
			paddingRight: `${tablePaddingLeftRight}px`,
		};

		const tableThStyle = {
			background: tableHeadBackground,
			fontFamily: tableHeadFontFamily,
			fontSize: `${tableHeadFontSize}px`,
			color: tableHeadFontColor,
			fontWeight: tableHeadIsBold ? 800 : 400,
			fontStyle: tableHeadIsItalic ? 'italic' : 'normal',
			textDecoration: tableHeadIsUnderLine ? 'underline' : 'none',
			textAlign: tableHeadAlignHor,
			// alignSelf: tableHeadAlignVer,
			verticalAlign: verticalAlignMap( tableHeadAlignVer ),
			borderColor: tableBorderColor,
			borderWidth: `${tableBorderWidth}px`,
			...tablePaddingStyle,
		};

		const tableTdStyle = {
			background: tableBodyBackground,
			fontFamily: tableBodyFontFamily,
			fontSize: `${tableBodyFontSize}px`,
			color: tableBodyFontColor,
			fontWeight: tableBodyIsBold ? 800 : 100,
			fontStyle: tableBodyIsItalic ? 'italic' : 'normal',
			textDecoration: tableBodyIsUnderLine ? 'underline' : 'none',
			textAlign: tableBodyAlignHor,
			// alignSelf: tableBodyAlignVer,
			verticalAlign: verticalAlignMap( tableBodyAlignVer ),
			borderColor: tableBorderColor,
			borderWidth: `${tableBorderWidth}px`,
			...tablePaddingStyle,
		};

		const tableContainerStyle = {
			// borderTopColor: 'red',
			// borderLeftColor: '#f0f0f0',
			borderTop: '1px solid #f0f0f0',
			borderLeft: '1px solid #f0f0f0',
			borderColor: `${tableBorderColor || '#f0f0f0'}`,
			borderWidth: `${tableBorderWidth || 1}px`,
		};


		// const tableRef: any = React.createRef();


		const MyTable = ( props ) => <table {...props} style={tableContainerStyle}></table>;
		const HeaderWrapper = ( props ) => <thead {...props}></thead>;
		const HeaderRow = ( props ) => <tr {...props} style={tableThStyle}></tr>;
		const HeaderCell = ( props ) => <th {...props} style={tableThStyle}></th>;
		const BodyWrapper = ( props ) => <tbody {...props}></tbody>;
		const BodyRow = ( props ) => <tr {...props}></tr>;
		const BodyCell = ( props ) => <td {...props} style={tableTdStyle}></td>;

		const components = {
			table: MyTable,
			header: {
				wrapper: HeaderWrapper,
				row: HeaderRow,
				cell: HeaderCell,
			},
			body: {
				wrapper: BodyWrapper,
				row: BodyRow,
				cell: BodyCell,
			},
		};

		const containerStyle = {
			// height: `calc(100% - ${tilteHight || 50}px)`,
		};

		return (
			<div id={this.props.id} className={styles.simple_table} style={containerStyle}>
				<Table
					// scroll={{ x: '100%' }}
					components={components}
					rowClassName={styles.simple_table_row}
					dataSource={this.state.tableData}
					columns={this.state.columns}
					pagination={false}
					rowKey={() => Math.random()} 
					bordered
					onRow={ ( record ) => {
						return {
							onClick: event => this.handleLink( record )
						};
					} }
					summary={( currentData ) => {
						const { openTotal, openColumnTotal, columns, tableType } = this.props.config.data;
						// 普通表格取columns，交叉表取转换后的树状结构的columns
						let arr = tableType === ORDINARY_CODE ? columns : this.state.columns;
						if ( !( openTotal && openColumnTotal ) || !arr ) {
							return null;
						}
						// 交叉表表头树状结构转平级结构
						if ( tableType === COMPLEX_CODE ) {
							arr = transformTreeData( [], this.state.columns ).filter( t => !t.children || !t.children.length );
						}
						const summaryData = arr.reduce( ( acc, cur ) => {
							acc[cur.dataIndex] = currentData.reduce( ( a, c ) => {
								let value = c[cur.dataIndex] || 0;
								// 去除千分号
								if ( value && value.indexOf( ',' ) !== -1 ) {
									value = value.replace( /[,]/g, '' );
								}
								return a + +value;
							}, 0 );
							return acc;
						}, {} );
						// console.log( currentData, arr, summaryData );
						return (
							<Table.Summary.Row>
							  {
								  arr.map( ( t, index ) => {
									  // 通过表头数据和summaryData的值取每列合计
									  if ( index === 0 ) {
											return <Table.Summary.Cell index={0}>合计</Table.Summary.Cell>;
									  } else {
											  let value = '-';
											  if ( t.modelType === DL_TYPE || tableType === COMPLEX_CODE ) {
												  value = summaryData[t.dataIndex].toFixed( 2 );
												  value = isNaN( +value ) ? '-' : value;
												  value = digitFormat( value, 3 );
											  }
											return <Table.Summary.Cell key={t.key} index={t.key}>{value}</Table.Summary.Cell>;
									  }
								  } )
							  }
							</Table.Summary.Row>
						  );
					}}
				/>
				<Pagination className={styles.simple_table_page} current={this.state.tableCurrentPage} total={this.state.tableTotal}
					onChange={this.handleTableChange} showQuickJumper showSizeChanger={false} pageSize={this.state.tablePageSize}
					showTotal={this.showTableTotal}/>
			</div>
		);
	}
}

export default SimpleTable;
